
var WindDate = new Object();

WindDate.createView = function() {
	var input = WindText.createView();
	
	input.isValid = function(value) {
		var valid = true;
		var empty = false;
		if(value==null && value.length<=0) {
			empty = true;
		}
		if(valid && !empty) {
			if(value.length!=10 && value.length!=16) {
				valid = false;
			}
		}
		if(valid && !empty) {
			if(value.length==16) {
				var day = value.substring(0,2);
				var month = value.substring(3,5);
				var year = value.substring(6,10);
				var hour = value.substring(11,13);
				var minute = value.substring(14,16);
				try {
					var date = new Date(year, month-1, day, hour, minute, 0);			
					if(!valid || year!=date.getFullYear()) {
						valid = false;
					} 
					if(!valid || (month-1)!=date.getMonth()) {
						valid = false;
					}
					if(!valid || day!=date.getDate()) {
						valid = false;
					}
					if(!valid || hour!=date.getHours()) {
						valid = false;
					}
					if(!valid || minute!=date.getMinutes()) {
						valid = false;
					}
				} catch (e) {
					valid = false
				}
			} else if (value.length==10) {
				var day = value.substring(0,2);
				var month = value.substring(3,5);
				var year = value.substring(6,10);
				try {
					var date = new Date(year, month-1, day);	
					if(!valid || year!=date.getFullYear()) {
						valid = false;
					} 
					if(!valid || (month-1)!=date.getMonth()) {
						valid = false;
					}
					if(!valid || day!=date.getDate()) {
						valid = false;
					}
				} catch (e) {
					valid = false
				}
			} else {
				valid = false;
			}
		}
		
		return valid;
	}

	input.getValueAsString = function(value) {
		var year = value.getFullYear()
		var month = value.getMonth() + 1;
		if(month<10) {
			month = "0" + month;
		}
		var day = value.getDate() + 1;
		if(day<10) {
			day = "0" + day
		}
		var hours = value.getHours();
		if(hours<10) {
			hours = "0" + hours;
		}
		var minutes = value.getMinutes();
		if(minutes<10) {
			minutes = "0" + minutes;
		}
		var str = month + "/" + day + "/" + year + " " + hours + ":" + minutes		
		return str;
	}

	return input;
}